package com.safeluck.scannerqcr.fragment;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.widget.Toolbar;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.safeluck.scannerqcr.R;
import com.safeluck.scannerqcr.fragment.shop.ContentFragment;
import com.safeluck.scannerqcr.fragment.shop.MenuFragment;

import java.util.ArrayList;
import java.util.Arrays;

import me.yokeyword.fragmentation.ISupportFragment;
import me.yokeyword.fragmentation.SupportFragment;

/**
 * ScannerQCR
 * Created by lzw on 2017/12/5. 10:38:05
 * 邮箱：632393724@qq.com
 * All Rights Saved! Chongqing AnYun Tech co. LTD
 */

public class WechatFourthTabFragment extends BaseMainFragment {


    private Toolbar mToobar;


    /**
     * 初始化Fragment
     * @return
     */
    public static SupportFragment newInstance() {
        Bundle bundle = new Bundle();
        WechatFourthTabFragment wechatFrout = new WechatFourthTabFragment();
        wechatFrout.setArguments(bundle);
        return  wechatFrout;
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.wechat_fragment_fourth_tab,container,false);
        initView(view);
        return view;
    }

    private void initView(View view) {
        mToobar = view.findViewById(R.id.toolbar);
        mToobar.setTitle("商店");
        if (findChildFragment(MenuFragment.class) == null) {
            ArrayList<String> listMenus = new ArrayList<>(Arrays.asList(getResources().getStringArray(R.array.array_menu)));
            loadRootFragment(R.id.fl_menu, MenuFragment.newInstance(listMenus));
            loadRootFragment(R.id.fl_content, ContentFragment.newInstance(listMenus.get(0)));
        }
    }

    @Override
    public void onLazyInitView(@Nullable Bundle savedInstanceState) {
        super.onLazyInitView(savedInstanceState);
    }


    public void switchFragment(ContentFragment iSupportFragment) {
        ContentFragment con =  findChildFragment(iSupportFragment.getClass());
        if (con != null){
            con.replaceFragment(iSupportFragment,false);
        }

    }
}
